package com.basic.business.pic.controller;


import com.basic.business.pic.domain.TGoodsPic;
import com.basic.business.pic.dto.TGoodsNoImgDto;
import com.basic.business.pic.service.ITGoodsPicService;
import com.basic.common.annotation.FileExport;
import com.basic.common.annotation.Log;
import com.basic.common.core.controller.BaseController;
import com.basic.common.core.domain.AjaxResult;
import com.basic.common.core.page.TableDataInfo;
import com.basic.common.enums.BusinessType;
import com.basic.common.utils.easyExcel.EasyExcelUtils;
import com.basic.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * 商品主图链接管理Controller
 *
 * @author zhaoxy_jn@163.com
 */
@RestController
@RequestMapping("/business/pic")
public class TGoodsPicController extends BaseController
{
    @Resource
    private ITGoodsPicService tGoodsPicService;

    /**
     * 查询商品主图链接管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:pic:list')")
    @GetMapping("/list")
    public TableDataInfo list(TGoodsPic tGoodsPic)
    {
        startPage();
        List<TGoodsPic> list = tGoodsPicService.getList(tGoodsPic);
        return getDataTable(list);
    }

    /**
     * 导出商品主图链接管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:pic:export')")
    @Log(title = "商品主图链接管理", businessType = BusinessType.EXPORT)
    @FileExport(fileName = "商品主图链接管理.xlsx")
    @PostMapping("/export")
    public String export(TGoodsPic tGoodsPic) throws IOException
    {
        List<TGoodsPic> list = tGoodsPicService.getList(tGoodsPic);
        return EasyExcelUtils.excelExport(TGoodsPic.class,"商品主图链接管理数据", list);
    }

    /**
     * 获取商品主图链接管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:pic:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tGoodsPicService.get(id));
    }

    /**
     * 新增商品主图链接管理
     */
    @PreAuthorize("@ss.hasPermi('business:pic:add')")
    @Log(title = "商品主图链接管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TGoodsPic tGoodsPic)
    {
        return toAjax(tGoodsPicService.insert(tGoodsPic));
    }

    /**
     * 修改商品主图链接管理
     */
    @PreAuthorize("@ss.hasPermi('business:pic:edit')")
    @Log(title = "商品主图链接管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TGoodsPic tGoodsPic)
    {
        return toAjax(tGoodsPicService.update(tGoodsPic));
    }

    /**
     * 删除商品主图链接管理
     */
    @PreAuthorize("@ss.hasPermi('business:pic:remove')")
    @Log(title = "商品主图链接管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tGoodsPicService.deleteByIds(ids));
    }

    /**
     * 导入数据
     */
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        tGoodsPicService.importFileData(file);
        return success("文件数据导入成功");
    }

    /**
     * 导出无上新日期商品数据
     */
    @FileExport(fileName = "无主图链接数据.xlsx")
    @PostMapping("/exportNoImg")
    public String exportNoImg() throws IOException
    {
        List<TGoodsNoImgDto> list = tGoodsPicService.exportNoImg();
        return EasyExcelUtils.excelExport(TGoodsNoImgDto.class,"无主图链接数据", list);
    }
}
